package cn.powertime.evaluation.web.controller;

import cn.powertime.evaluation.entity.KbKnowledgeBase;
import cn.powertime.evaluation.entity.KbKnowledgeBaseContent;
import cn.powertime.evaluation.facade.KbKnowledgeBaseFacade;
import cn.powertime.evaluation.vo.ParamPageVo;
import cn.powertime.evaluation.vo.ReqKnowledgeBaseSearchVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 知识表 前端控制器
 * </p>
 *
 * @author liqi
 * @since 2019-09-27
 */
@RestController
@RequestMapping("/web/knowledgeBase")
@Api(value = "/web/knowledgeBase", tags = "知识库接口", produces = MediaType.ALL_VALUE)
@Validated
public class KbKnowledgeBaseController extends BaseController {

    @Autowired
    private KbKnowledgeBaseFacade knowledgeBaseFacade;

    @ApiOperation(value = "知识库-目录列表接口")
    @PostMapping(value = "/list")
    public Object list(@Validated @RequestBody ParamPageVo<ReqKnowledgeBaseSearchVo> vo) {
        IPage<KbKnowledgeBase> list = this.knowledgeBaseFacade.knowledgeBaseList(vo);
        return success(list);
    }

    @ApiOperation(value = "知识库-目录详情接口")
    @PostMapping(value = "/details")
    public Object details(@NotNull(message = "id不能为空") @RequestParam Long id) {
        KbKnowledgeBase knowledgeBase = this.knowledgeBaseFacade.details(id);
        return success(knowledgeBase);
    }

    @ApiOperation(value = "知识库-目录内容接口")
    @PostMapping(value = "/content")
    public Object content(@NotNull(message = "id不能为空") @RequestParam Long rootId) {
        List<KbKnowledgeBaseContent> list = this.knowledgeBaseFacade.content(rootId);
        return success(list);
    }

}
